package tarena.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.ImmutableList;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.springframework.data.annotation.Transient;

import java.util.Date;
import java.util.List;

/**
* @author Leslie
*/

@Data
public class TabAccount {

	public TabAccount() {
	}
	
	private Long id; //
	private Date createDate; //
	private Date updateDate; //
	private Integer deleted; //
	private String loginName; //
	private String password; //

	private String salt; //
	private String roles; //
	private String uid; //


	private String name; //
    
   
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}

	//-------------------------------以下是追加的代码-------------------------------------------------
	private String plainPassword;

	@Transient
	@JsonIgnore
	public List<String> getRoleList() {
		// 角色列表在数据库中实际以逗号分隔字符串存储，因此返回不能修改的List.
		return ImmutableList.copyOf(StringUtils.split(roles, ","));
	}

	@Transient
	public String getPlainPassword() {
		return plainPassword;
	}

	public void setPlainPassword(String plainPassword) {
		this.plainPassword = plainPassword;
	}


}